{template 'common/header'}
<ul class="nav nav-tabs">
<li {if $op=='display'}class="active"{/if}><a href="{php echo $this->createWebUrl('category',array('op'=>'display'));}">管理</a></li>
<li {if $op =='post'&&empty($id)}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('op' => 'post'));}">添加分类</a></li>
{if !empty($id) && $op=='post'}
<li class="active"> <a href="{php echo $this->createWebUrl('category',array('op'=>'post','id'=>$id,'parentid'=>$parentid));}">编辑分类</a></li>
{/if}
</ul>
<div style="margin:0;" class="alert alert-info"><i class="icon-warning-sign"></i>
	注意：所有列表支持二级目录,一级目录相当于入口，也就是说可以设置一级目录做完菜单链接，子目录作为页面显示内容<br>
	在子分类增加文章 ，入口可以使用连接，也可以使用关键字返回。 
	关键字优先级  父分类的关键字查找关联分类下面的文章，以图文格式显示<br>
	<span style="font-weight:bold;">建议：每个分类模板 建一个父分类，一级分类相当于一个微站的入口，这样可以给多个公众号建立。
	文章建议加在子分类上</span>
</div>
{if $op=='post'}

<div class="main">
	<form action="" method="post" class="form-horizontal form" id="form1">
	<input type="hidden" name="parentid" value="{$parent['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">分类详细设置</div>
			<div class="panel-body">
				{if !empty($category['name'])}
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">访问地址</label>
					<div class="col-sm-8 col-xs-12">
						<div class="form-control-static"><a href= " target="_blank">
                            {if $category['template']==12}
                            <a class="preview_url" href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$category[id],'op'=>'wemedia'),true),2);}" target="_blank">
                                {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$category[id],'op'=>'wemedia'),true),2);}
                            </a>
                            {else}
                            <a class="preview_url" href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$category[id]),true),2);}" target="_blank">
                                {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$category[id]),true),2);}
                            </a>
                            {/if}
                        </div>
						<span class="help-block">您可以根据此地址，添加回复规则，设置访问。</span>
					</div>
				</div>
				{/if}
				{if $parentid>0}
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">上级分类</label>
					<div class="col-sm-8 col-xs-12">
						<div class="form-control-static">{$parent['name']}</div>
					</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">排序</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" name="displayorder" class="form-control" value="{$category['displayorder']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">分类名称</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" name="cname" class="form-control" value="{$category['name']}" />
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">文章触发关键字</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" class="form-control" placeholder="" name="keyword" value="{$keywords}">
						<div class="help-block">添加关键字以后,系统将生成一条图文规则</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">分类描述</label>
					<div class="col-sm-8 col-xs-12">
						<textarea name="description" class="form-control" cols="70">{$category['description']}</textarea>
					</div>
				</div>

				<div class="form-group clearfix">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">选择分类风格</label>
                    <div class="col-sm-8 col-xs-12">
                        {template 'c_tpl'}
					</div>
				</div>

  			</div>
		</div>

        {if $parentid>0}
		<div class="panel panel-default" id="style">
			<div class="panel-heading">导航图标</div>
			<div class="panel-body">
				<div class="" id="iconuser">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">上传图标</label>
						<div class="col-sm-9 col-xs-12">
							{php echo tpl_form_field_image('thumb', $category['thumb']);}
						</div>
					</div>
				</div>
			</div>
		</div>
        {/if}

	<div class="form-group">
		<div class="col-sm-12">
			<input name="submit" type="submit" value="提交" class="btn btn-primary col-lg-1">
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</div>
	</form>
</div>
<script type="text/javascript">
<!--
	require(['jquery', 'util'], function($, u){
		$("#form1").submit(function(){
			if($("input[name='cname']").val() == '') {
				u.message('请输入分类名称', '', 'error');
				return false;
			}
		});
	});
//-->
</script>
{elseif $op == 'display'}
<div class="main">
	<div class="category">
		<form action="" method="post" onsubmit="return formcheck(this)">
		<div class="panel panel-default">
		<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead>
				<tr>
					<th style="width:10%;">显示顺序</th>
					<th style="width:15%;">分类名称</th>
					<th style="width:50%;">链接</th>
					<th style="width:20%;text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
			{loop $category $row}
				<tr>
                    <td class="text-center">
                        <input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}">
                    </td>

					<td class="text-left">
                        <div style="height:30px;line-height:30px">{$row['name']}&nbsp;&nbsp;
                        {if empty($row['parentid'])}
                        <a href="{php echo $this->createWebUrl('category',array('op'=>'post','parentid'=>$row['id']));}" title="添加子分类">
                            <i class="fa fa-plus">子分类</i>
                        </a>
                        {/if}
                        </div>
                    </td>
					<td>
                        {if $row['template']==12}
                        <a class="preview_url" href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id],'op'=>'wemedia'),true),2);}" target="_blank">
                            {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id],'op'=>'wemedia'),true),2);}
                        </a>
                        {elseif $row['template']==14}
                        <a class="preview_url" href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}" target="_blank">
                            {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}
                        </a>
                        {else}
                        <a class="preview_url" href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}" target="_blank">
                            {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}
                        </a>
                        {/if}

                    </td>
					<td class="text-center">
						{if $row['template']==12|| $row['template']==14}
                        <a href="{php echo $this->createWebUrl('slide', array('op' => 'post', 'pid' => $row['id']))}" title="添加幻灯片" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-plus">幻灯片</i></a>
						{else}
						<a href="{php echo $this->createWebUrl('slide', array('op' => 'post', 'pid' => $row['id']))}" title="添加幻灯片" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-plus">幻灯片</i></a>
						<a href="{php echo $this->createWebUrl('paper', array('op' => 'post', 'pcate' => $row['parentid'], 'ccate' => $row['id']))}" title="添加文章" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-plus">添加文章</i></a>
						{/if}
                        <a href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $row['id']))}" title="编辑" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-edit"></i></a>
                        <a href="{php echo $this->createWebUrl('category', array('op' => 'delete','id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{loop $children[$row['id']] $row}
				<tr>
					<td class="text-center"><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}">
                    </td>
					<td class="text-left">
                    <div style="padding-left:50px;height:30px;line-height:30px;background:url('./resource/images/bg_repno.gif') no-repeat -245px -545px;">{$row['name']}&nbsp;&nbsp;
                            {if empty($row['parentid'])}
                            <a href="{php echo url('category', array('foo' => 'post', 'parentid' => $row['id']))}">
                                <i class="fa fa-plus" title="添加子分类"></i></a>
                            {/if}
                    </div>
                    </td>
					<td class="text-center">
                       <!-- <a href="{php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}" target="_blank">
                        {php echo $_W['siteroot'].'app/'.substr($this->createMobileUrl('index',array('cid'=>$row[id]),true),2);}
                        </a>-->
                    </td>
					<td class="text-center">
                        <a href="{php echo $this->createWebUrl('paper', array('op' => 'post', 'pcate' => $row['parentid'], 'ccate' => $row['id']))}" title="添加文章" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-plus">添加文章</i></a>
                        <a href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $row['id'], 'parentid' => $row['parentid']))}" title="编辑" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-edit"></i></a>
                        <a href="{php echo $this->createWebUrl('category', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}
			{/loop}
				<tr>
					<td colspan="5">
                        <a href="{php echo $this->createWebUrl('category', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加新分类</a>
					</td>
				</tr>
			</tbody>
		</table>
		</div>
		</div>
			<div class="form-group col-sm-12">
				<input name="submit" type="submit" class="btn btn-primary col-lg-1" value="提交">
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</form>
	</div>
</div>
<script>
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
</script>
{/if}
{template 'common/footer'}
